/**
 * 
 */
package com.chinasofti.project.service.user.impl;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chinasofti.project.dal.mapper.BzUserMapper;
import com.chinasofti.project.dal.model.BzUser;
import com.chinasofti.project.service.user.result.MoneyManageResult;

/**
 * @author liuji
 *
 */
@Service("moneyManageService")
public class MoneyManageServiceImpl implements com.chinasofti.project.service.user.MoneyManageService {
	@Autowired
	public BzUserMapper bzUserMapper;

	@Override
	public MoneyManageResult rechargeAmount(BzUser bzUser, BigDecimal money) {
		BzUser sqlUser = bzUserMapper.selectByPrimaryKey(bzUser.getUserId());
		MoneyManageResult m = new MoneyManageResult();
		if (sqlUser.getUserPayPassword() == "" || sqlUser.getUserPayPassword() == null) {
			m.setStateResult("支付密码不存在");
			return m;
		} else {
			if (!(bzUser.getUserPayPassword().equals(sqlUser.getUserPayPassword()))) {
				m.setStateResult("支付密码不正确");
				return m;
			} else {
				BigDecimal sqlMoney = sqlUser.getUserBalance();
				BigDecimal userBalance = new BigDecimal(sqlMoney.add(money).doubleValue());
				bzUser.setUserBalance(userBalance);
				bzUserMapper.updateByPrimaryKeySelective(bzUser);
				m.setStateResult("充值成功");
				return m;
			}
		}
	}

	@Override
	public BzUser queryUser(int userId) {
		return bzUserMapper.selectByPrimaryKey(userId);
	}

}
